;递归版本
(define (accumulate combiner null-value term a next b)
  (if (> a b)
    null-value
    (combiner (term a) (accumulate combiner null-value (next a) next b))))

;迭代版本
(define (accumulate combiner null-value term a next b)
  (define (product-iter a result)
    (if (> a b)
      result
      (product-iter (next a) (combiner result (term a)))))
  (product-iter a null-value))

(define (sum term a next b)
  (accumulate + 0 term a next b))

(define (product term a next b)
  (accumulate * 1 term a next b))
